#ifndef THINK_THINK_CONSOLE_OUTPUT_FORMATTER_STACK_H
#define THINK_THINK_CONSOLE_OUTPUT_FORMATTER_STACK_H

static char* think_console_output_formatter_stack =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: yunwuxin <448901948@qq.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\console\\output\\formatter;\n"
	"\n"
	"class Stack\n"
	"{\n"
	"\n"
	"    /**\n"
	"     * @var Style[]\n"
	"     */\n"
	"    private $styles;\n"
	"\n"
	"    /**\n"
	"     * @var Style\n"
	"     */\n"
	"    private $emptyStyle;\n"
	"\n"
	"    /**\n"
	"     * 构造方法\n"
	"     * @param Style|null $emptyStyle\n"
	"     */\n"
	"    public function __construct(Style $emptyStyle = null)\n"
	"    {\n"
	"        $this->emptyStyle = $emptyStyle ?: new Style();\n"
	"        $this->reset();\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 重置堆栈\n"
	"     */\n"
	"    public function reset()\n"
	"    {\n"
	"        $this->styles = [];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 推一个样式进入堆栈\n"
	"     * @param Style $style\n"
	"     */\n"
	"    public function push(Style $style)\n"
	"    {\n"
	"        $this->styles[] = $style;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 从堆栈中弹出一个样式\n"
	"     * @param Style|null $style\n"
	"     * @return Style\n"
	"     * @throws \\InvalidArgumentException\n"
	"     */\n"
	"    public function pop(Style $style = null)\n"
	"    {\n"
	"        if (empty($this->styles)) {\n"
	"            return $this->emptyStyle;\n"
	"        }\n"
	"\n"
	"        if (null === $style) {\n"
	"            return array_pop($this->styles);\n"
	"        }\n"
	"\n"
	"        /**\n"
	"         * @var int   $index\n"
	"         * @var Style $stackedStyle\n"
	"         */\n"
	"        foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {\n"
	"            if ($style->apply(\'\') === $stackedStyle->apply(\'\')) {\n"
	"                $this->styles = array_slice($this->styles, 0, $index);\n"
	"\n"
	"                return $stackedStyle;\n"
	"            }\n"
	"        }\n"
	"\n"
	"        throw new \\InvalidArgumentException(\'Incorrectly nested style tag found.\');\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 计算堆栈的当前样式。\n"
	"     * @return Style\n"
	"     */\n"
	"    public function getCurrent()\n"
	"    {\n"
	"        if (empty($this->styles)) {\n"
	"            return $this->emptyStyle;\n"
	"        }\n"
	"\n"
	"        return $this->styles[count($this->styles) - 1];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * @param Style $emptyStyle\n"
	"     * @return Stack\n"
	"     */\n"
	"    public function setEmptyStyle(Style $emptyStyle)\n"
	"    {\n"
	"        $this->emptyStyle = $emptyStyle;\n"
	"\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * @return Style\n"
	"     */\n"
	"    public function getEmptyStyle()\n"
	"    {\n"
	"        return $this->emptyStyle;\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif